package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {
    @Autowired
    GraphInfoMapper graphInfoMapper;

    @Autowired
    LabelInfoMapper labelInfoMapper;

    @Autowired
    FacilityInfoMapper facilityInfoMapper;

    @Autowired
    ApartmentInfoMapper apartmentInfoMapper;


    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        ApartmentInfo apartmentInfo = baseMapper.selectById(id);
        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);

        List<GraphVo> graphVoList = graphInfoMapper.selectApartmentGraphList(id);
        apartmentDetailVo.setGraphVoList(graphVoList);

        List<LabelInfo> labelInfoList = labelInfoMapper.selectApartmentLabelInfoListById(id);
        apartmentDetailVo.setLabelInfoList(labelInfoList);

        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectApartmentFacilityInfoListById(id);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);

        apartmentDetailVo.setIsDelete(apartmentInfo.getIsDeleted().equals(1));

        BigDecimal minRent = apartmentInfoMapper.selectMinRent(id);
        apartmentDetailVo.setMinRent(minRent);

        return apartmentDetailVo;
    }

    @Override
    public ApartmentItemVo getApartmentItemVoById(Long apartmentId) {
        ApartmentItemVo apartmentItemVo = new ApartmentItemVo();
        ApartmentInfo apartmentInfo = baseMapper.selectById(apartmentId);
        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);
        apartmentItemVo.setLabelInfoList(labelInfoMapper.selectApartmentLabelInfoListById(apartmentId));
        apartmentItemVo.setGraphVoList(graphInfoMapper.selectApartmentGraphInfo(apartmentId));
        BigDecimal minRent = apartmentInfoMapper.selectMinRent(apartmentId);
        apartmentItemVo.setMinRent(minRent);
        return apartmentItemVo;

    }


}




